#ifndef PY_COMPAT_H
#define PY_COMPAT_H

#include <Python.h>

// Python 3.12+ compatibility fixes
#if PY_VERSION_HEX >= 0x030C0000

// Define Py_UNICODE as wchar_t for compatibility
#ifndef Py_UNICODE
#define Py_UNICODE wchar_t
#endif

// Define PyUnicode_AsUnicode replacement
static inline Py_UNICODE* PyUnicode_AsUnicode(PyObject *unicode) {
    return (Py_UNICODE*)PyUnicode_AsWideCharString(unicode, NULL);
}

// Define PyUnicode_FromUnicode replacement
static inline PyObject* PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size) {
    if (size < 0) {
        size = wcslen(u);
    }
    return PyUnicode_FromWideChar(u, size);
}

// Define PyUnicode_READ_CHAR replacement
#ifndef PyUnicode_READ_CHAR
#define PyUnicode_READ_CHAR(unicode, index) PyUnicode_ReadChar(unicode, index)
#endif

#endif // PY_VERSION_HEX >= 0x030C0000

#endif // PY_COMPAT_H
